﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/static/lib/html5.js"></script>
<script type="text/javascript" src="/static/lib/respond.min.js"></script>
<script type="text/javascript" src="/static/lib/PIE_IE678.js"></script>
<![endif]-->
<link href="/static/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="/static/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="/static/css/style.css" rel="stylesheet" type="text/css" />
<link href="/static/lib/font-awesome/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!--[if IE 7]>
<link href="lib/font-awesome/font-awesome-ie7.min.css" rel="stylesheet" type="text/css" />
<![endif]-->
<link href="/static/lib/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>文章列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="iconfont">&#xf012b;</i> 首页 <span class="c-gray en">&gt;</span> 文章管理 <span class="c-gray en">&gt;</span> 文章列表 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="icon-refresh"></i></a></nav>
<div class="pd-20">
<form  id="search_form">
  <div class="text-c">
  <span class="select-box" style="width:150px"><select name="category" class="select" id="cateoption">
  </select></span> 日期范围：
    <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}'})" id="logmin" name="endDate" class="input-text Wdate" style="width:120px;">
    -
    <input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d'})" id="logmax" name="startDate" class="input-text Wdate" style="width:120px;">
    <input type="text" name="keyword" id="keyword" placeholder=" 文章名称" style="width:250px" class="input-text"><button onclick="search();" id="search_btn" class="btn btn-success" type="button" ><i class="icon-search"></i> 搜文章</button>
  </div>
</form>
  <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="batch_del('/admin/article/batchDel')" class="btn btn-danger radius"><i class="icon-trash"></i> 批量删除</a> <a class="btn btn-primary radius" onclick="_add('添加文章','/page/admin/article/article-add.html')"  href="javascript:;"><i class="icon-plus"></i> 添加文章</a></span> <span class="r">共有数据：<strong id="totalRow"></strong> 条</span> </div>
  <table class="table table-border table-bordered table-bg table-hover table-sort">
    <thead>
      <tr class="text-c">
        <th width="25"><input type="checkbox" name="" value=""></th>
        <th width="80">ID</th>
        <th>标题</th>
        <th width="80">分类</th>
        <th width="80">来源</th>
        <th width="120">更新时间</th>
        <th width="75">浏览次数</th>
        <th width="60">发布状态</th>
        <th width="100">操作</th>
      </tr>
    </thead>
    <tbody id="data_list" >
    </tbody>
  </table>
   <div class="view" style="margin: 10px auto;float: left;"></div>
  <div class="page" style="margin: 10px auto;float: right;"></div>
  <!-- <div id="pageNav" class="pageNav"></div> -->
</div>
<script type="text/javascript" src="/static/lib/jquery.min.js"></script>
<script type="text/javascript" src="/static/lib/layer2.1/layer.js"></script>
<script type="text/javascript" src="/static/lib/laypage/laypage.js"></script> 
<script type="text/javascript" src="/static/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/static/lib/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/static/js/H-ui.js"></script>
<script type="text/javascript" src="/static/js/H-ui.admin.js"></script> 
<script type="text/javascript" src="/static/js/H-ui.admin.doc.js"></script>
<script type="text/javascript">
$(function(){
	getDataList();
	getCateList();
});

function getDataList(curr){
	var json = $("#search_form").toJson();
	$.post(
			 '/admin/article',
			{
				page : curr||1,
				params:json
			}, function(obj) {
				var data = obj.list;
				var innerHtml = "";
				$.each(data, function(index) {
					//alert(data);
					//拆解 category 和tags  的list集合
					var cates = "";
					var tags = "";
					$.each(this.categories,function(i){
						cates+=this.name+",";
					});
					cates = cates.substring(0,cates.length-1);
					$.each(this.tags,function(i){
						tags+=this.name+",";
					});
					tags = tags.substring(0,tags.length-1);
					var edit = '';
					var deleted; //
					var de_name="已禁用";
					if(this.deleted){
						if(this.status=="0"){ //草稿
							deleted = false;
							de_name="草稿";
							edit='<td class="f-14 user-manage"><a style="text-decoration:none" onClick="operate_start_article(this,'+this.id+');" href="javascript:void(0);" title="发布"><i class="icon-hand-up"></i></a>';
						}else{//启用
							deleted = true;
							edit='<td class="f-14 user-manage"><a style="text-decoration:none" onClick="operate_stop_article(this,'+this.id+');" href="javascript:void(0);" title="停用"><i class="icon-hand-down"></i></a>';
						}
					}else{
						deleted = false;
						if(this.status=="0"){ //草稿
							de_name="草稿";
						}
						edit='<td class="f-14 user-manage"><a style="text-decoration:none" onClick="operate_start_article(this,'+this.id+');" href="javascript:void(0);" title="启用"><i class="icon-hand-up"></i></a>';
					}
					innerHtml+='<tr class="text-c"><td><input type="checkbox" value="'+this.id+'" name="id"></td> '
					+'<td>'+this.id+'</td><td>'+this.title+'</td><td>'+cates+'</td><td>'+tags+'</td><td>'+this.update_date+'</td><td>'+this.read_count+'</td><td class="user-status"><span class="label '+(deleted?"label-success":"")+' radius">'+(deleted?"已发布":de_name)+'</span></td>'
					+edit+' <a title="编辑" href="javascript:;" onclick="show_layer('+this.id+')" class="ml-5" style="text-decoration:none"><i class="icon-edit"></i></a>  <a title="删除" href="javascript:;" onclick="operate_del_article(this,'+this.id+')" class="ml-5" style="text-decoration:none"><i class="icon-trash"></i></a></td></tr>';
				});
				$("#data_list").html(innerHtml);
				$("#totalRow").html(obj.totalRow);
				laypage({
				    cont: $('.page'), //容器。值支持id名、原生dom对象，jquery对象,
				    pages: obj.totalPage, //总页数
				    curr: curr || 1, //当前页
				    skip: false, //是否开启跳页
				    skin: 'molv',
				    groups: 3, //连续显示分页数
				    first: '首页', //若不显示，设置false即可
				    last: '尾页', //若不显示，设置false即可
				    prev: '<', //若不显示，设置false即可
				    next: '>', //若不显示，设置false即可
				    hash: true, //开启hash
				    jump: function(obj,first){ //触发分页后的回调
				        $('.view').html('目前正在第'+ obj.curr +'页，一共有：'+ obj.pages +'页');
				    	if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
				    		getDataList(obj.curr);
		                }
				    }
				});
				
		},"json");
}
//获取类别列表
function getCateList(){
	$.post("/admin/category/getAll", function(data){
		var $html  = $("#cateoption");
		$html.empty().append(" <option value=''>全部分类</option>");
		$.each(data, function(index) {
			$html.append("<option value='"+this.name+"'>"+this.name+"</option>");
		});
		
	});
}
/*文章-添加*/
function _add(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
//弹出层
function show_layer(id){
	var url = "/admin/article/toEdit?id="+id;
	var index = layer.open({
		type: 2,
		title: "编辑",
		content: url
	});
	layer.full(index);
	//user_edit("1","600","400","编辑",url);
}
//批量删除
function batch_del(url){
	// 判断是否至少选择一项 
	var checkedNum = $("input[name='id']:checked").length;
	if (checkedNum == 0) {
		layer.msg('请至少选择一项！',{time: 1000, icon:6});
		return;
	}else{
		layer.confirm('确认要删除这'+checkedNum+'项吗？',function(index){
			var checkedList = new Array();
			$("input[name='id']:checked").each(function() {
				checkedList.push($(this).val());
			});
			var arr = checkedList.toString();
			$.post(url, {ids:arr}, function(data){
				if('1006'!=data.code){
					layer.msg('删除失败!',{time: 1000, icon:6});
				}else{
					layer.msg('删除成功!',{time: 1000, icon:6},function(){
						getDataList();
					});
				}
			});  
		});
	    
	}
	
}
function operate_del_article(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.post("/admin/article/batchDel",{ids :id}, function(data) {
			if(data.code!="1006"){
				layer.msg(data.description,{time: 1000, icon:6});
			}else{
				//$(obj).parents("tr").remove();
				getDataList();
				layer.msg(data.description,{time: 1000, icon:6});
			}
					
			}
		 );
		
	});
}
/*用户-停用*/
function operate_stop_article(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		$.post("/admin/article/operate",{id :id,type:"no"}, function(data) {
			if(data.code!="1006"){
				layer.msg('操作失败!',{time: 1000, icon:6});
			}else{
				$(obj).parents("tr").find(".user-manage").prepend('<a style="text-decoration:none" onClick="user_start(this,\'10001\')" href="javascript:;" title="启用"><i class="icon-hand-up"></i></a>');
				$(obj).parents("tr").find(".user-status").html('<span class="label radius">已禁用</span>');
				$(obj).remove();
				layer.msg('已停用!',{time: 1000, icon:6});
			}
			}
		 );
	
		
	});
}
/*用户-启用*/
function operate_start_article(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		$.post("/admin/article/operate",{id :id,type:"yes"}, function(data) {
			if(data.code!="1006"){
				layer.msg('操作失败!',{time: 1000, icon:6});
			}else{
				$(obj).parents("tr").find(".user-manage").prepend('<a style="text-decoration:none" onClick="user_stop(this,\'10001\')" href="javascript:;" title="停用"><i class="icon-hand-down"></i></a>');
				$(obj).parents("tr").find(".user-status").html('<span class="label label-success radius">已发布</span>');
				$(obj).remove();
				layer.msg('已启用!',{time: 1000, icon:6});
			}
			}
		 );
		
	});
}
//搜索
function search(url){
	getDataList();
}
</script> 
</body>
</html>